package com.itheima.optimizeserver.threadsocket;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 10003);
        //Socket socket = new Socket();
        // 本地流
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("ClientDir\\1.jpg"));

        OutputStream os = socket.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);

        int b;
        while ((b = bis.read()) != -1) {
            // 通过网络写到服务器
            bos.write(b);
        }
        // 告诉服务器文件已经传输完毕
        socket.shutdownOutput();

        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

        socket.close();
        bis.close();
    }
}
